package com.hicar.service;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MenuService {
	private static Gson gson = new Gson();

	private List<Map<String, Object>> menus = new ArrayList<>();

	public MenuService() {
		Resource resource = new ClassPathResource("data/sidebar.json");

		try (InputStream in = resource.getInputStream();
				Reader reader = new InputStreamReader(in)) {

			menus = gson.fromJson(reader,
					new TypeToken<List<Map<String, Object>>>() {
					}.getType());
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	public List<Map<String, Object>> getMenus() {
		return menus;
	}
}
